package com.gen.common.constant.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import com.gen.entity.User.UserStatus;

public class UserStatusHandler implements TypeHandler<UserStatus> {

	public UserStatus getResult(CallableStatement paramCallableStatement, int paramInt) throws SQLException {
		String str = paramCallableStatement.getString(paramInt);
		if (UserStatus.ACTIVE.value().equals(str))
			return UserStatus.ACTIVE;
		if (UserStatus.OWED.value().equals(str))
			return UserStatus.OWED;
		if (UserStatus.FROZEN.value().equals(str))
			return UserStatus.FROZEN;
		if (UserStatus.INACTIVE.value().equals(str))
			return UserStatus.INACTIVE;
		return UserStatus.LOGICAL_DELETED;
	}

	public UserStatus getResult(ResultSet paramResultSet, int paramInt) throws SQLException {
		String str = paramResultSet.getString(paramInt);
		if (UserStatus.ACTIVE.value().equals(str))
			return UserStatus.ACTIVE;
		if (UserStatus.OWED.value().equals(str))
			return UserStatus.OWED;
		if (UserStatus.FROZEN.value().equals(str))
			return UserStatus.FROZEN;
		if (UserStatus.INACTIVE.value().equals(str))
			return UserStatus.INACTIVE;
		return UserStatus.LOGICAL_DELETED;
	}

	public UserStatus getResult(ResultSet paramResultSet, String paramString) throws SQLException {
		String str = paramResultSet.getString(paramString);
		if (UserStatus.ACTIVE.value().equals(str))
			return UserStatus.ACTIVE;
		if (UserStatus.OWED.value().equals(str))
			return UserStatus.OWED;
		if (UserStatus.FROZEN.value().equals(str))
			return UserStatus.FROZEN;
		if (UserStatus.INACTIVE.value().equals(str))
			return UserStatus.INACTIVE;
		return UserStatus.LOGICAL_DELETED;
	}

	public void setParameter(PreparedStatement paramPreparedStatement, int paramInt, UserStatus paramT, JdbcType paramJdbcType)
			throws SQLException {
		if (paramT == null) {
			paramPreparedStatement.setString(paramInt, "");
			return;
		}
		paramPreparedStatement.setString(paramInt, paramT.value());
	}

}
